﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "formatcontroller.h" 
#include "ribbontoolbar.h"
#include "iformatpanel.h"          
#include "editorwidget.h"         
#include "menubar.h"
#include "documenttabwidget.h"
#include <QMainWindow>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSplitter>
#include <QStackedWidget>


class MainWindow : public QMainWindow
{
	Q_OBJECT

public:
	MainWindow(QWidget* parent = nullptr);
	~MainWindow() override;

private:

	void initUI();
	void initController();
	void addNewDocumentTab();
	void onTabSwitched(int index);
	void onSaveDocument();
	void onSaveAsDocument();
	void onOpenDocument();
	void onTabCloseRequested(int index, const QString& key);
	bool saveToFile(EditorWidget* editor, const QString& filePath);
	bool loadFileToEditor(const QString& filePath, EditorWidget* editor);
	QString readFileWithEncoding(const QString& filePath);
	void doCloseTab(int index, const QString& key, EditorWidget* editor);
	EditorWidget* getEditorByKey(const QString& key);

	RibbonToolbar* m_ribbon;        
	IFormatPanel* m_sidebar;    
	FormatController* m_formatController; 
	QSplitter* m_splitter;
	QStackedWidget* m_editorStack; 
	MenuBar* m_menubar;
	DocumentTabWidget* m_documenttabs;
	QList<EditorWidget*> m_editors;
	QHash<QString, QString> m_filePaths; 
	QHash<QString, QString> m_fileFormats;  

};

#endif // MAINWINDOW_H
